package org.dromara.exam.util;

import lombok.SneakyThrows;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

/**
 * @author xiyin321
 */
public final class HTTPUtils {

    /**
     * @param fileName 获取下载文件名，避免中文文件名乱码
     */
    @SneakyThrows
    public static String getContentDispositionValue(String fileName) {
        // 对真实文件名进行百分号编码
        String percentEncodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8).replaceAll("\\+", "%20");

        // 组装contentDisposition的值
        return "attachment; filename=" + percentEncodedFileName;

    }

}
